package com.enjoy.ch1;

import sun.misc.Launcher;

import java.net.URL;

/**
 * 演示三个类加载器加载的路径
 */
public class TestJDKClassloader {
    public static void main(String[] args) {
        System.out.println(String.class.getClassLoader());
        System.out.println(com.sun.crypto.provider.DESKeyFactory.class.getClassLoader());
        System.out.println(TestJDKClassloader.class.getClassLoader());

        System.out.println();

        ClassLoader appClassLoader = ClassLoader.getSystemClassLoader();
        ClassLoader extClassLoader = appClassLoader.getParent();
        ClassLoader bootStrapClassLoader = extClassLoader.getParent();
        System.out.println("appClassLoader " + appClassLoader);
        System.out.println("extClassLoader " + extClassLoader);
        System.out.println("bootStrapClassLoader " + bootStrapClassLoader);

        System.out.println();
        System.out.println("bootstrapClassloader加载以下文件");
        URL[] urLs = Launcher.getBootstrapClassPath().getURLs();
        for (URL urL : urLs) {
            System.out.println(urL);
        }

        System.out.println();
        System.out.println("extClassloader加载以下文件");
        System.out.println(System.getProperty("java.ext.dirs"));

        System.out.println();
        System.out.println("appClassloader加载以下文件");
        String classPath = System.getProperty("java.class.path");
        String[] strings = classPath.split(";");
        for (String str : strings) {
            System.out.println(str);
        }

    }
}
